const app = new Vue({
	el: "#app",
	data: {
		books: [{
				id: 1,
				name: "《算法编导》",
				price: 85.00,
				time: "2020-6-18",
				count: 1
			},
			{
				id: 2,
				name: "《UNIX编程艺术》",
				price: 65.00,
				time: "2020-6-18",
				count: 1
			},
			{
				id: 3,
				name: "《编程珠玑》",
				price: 75.00,
				time: "2020-6-18",
				count: 1
			},
			{
				id: 4,
				name: "《代码大全》",
				price: 95.00,
				time: "2020-6-18",
				count: 1
			},
		]
	},
	computed: {
		totalPrice() {
			let totalPrice = 0;
			for (let i = 0; i < this.books.length; i++) {
				totalPrice += this.books[i].price * this.books[i].count
			}
			return totalPrice;
		}

	},
	methods: {
		add(index) {
			this.books[index].count++;
		},
		sub(index) {
			this.books[index].count--;
		},
		btnClick(index) {
			this.books.splice(index, 1)
		}
	},
	filters: {
		showPrice(price) {
			return "￥" + price.toFixed(2);
		}
	}

})
